using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Admin3000.Backend.Api.Utils
{
    public class JsonHelper
    {
        public static string Serialize(dynamic obj)
        {
            //年份-月份-日期  小时:分钟:秒钟
            var datetimeformat = "yyyy-MM-dd HH:mm:ss";
            //  序列化实现驼峰命名法（首字母小写，其余的单词首字母都是大写）
            var setting = new JsonSerializerSettings();
            setting.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();

            //转换为字符串类型
            setting.DateFormatString = datetimeformat;
            //转换日期
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = datetimeformat };
            var result = JsonConvert.SerializeObject(obj, Formatting.Indented, setting);
            return result;
        }
    }
}